"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".

Replace these with more appropriate tests for your application.
"""

from django.test import TestCase

class GraphDataTest(TestCase):
    def test_recount(self):
        from DjangoSite.kburndown.models import GraphData
        GraphData(date="2010-9-7", value=100).save()
        from DjangoSite.kburndown.models import Unit
        Unit(name="WOWTEXT", member_count=8).save()
        Unit(name="WOWET", member_count=4).save()
        Unit(name="UI", member_count=6).save()
        Unit.objects.all()
        from DjangoSite.kburndown.service import add_task
        add_task(None, "T1", None, 1, 5)
        add_task(None, "T2", None, 1, 3)
        add_task(None, "T3", None, 1, 1)
        add_task(None, "T4", None, 2, 2)
        add_task(None, "T5", None, 2, 7)
        add_task(None, "T6", None, 3, 1)
        add_task(None, "T7", None, 3, 4)
        add_task(None, "T8", None, 3, 5)

        sum=GraphData.objects.order_by('-date')[0].value
        self.failUnlessEqual(sum, 168, \
                             "GraphDataTest: test_recount failed on section 1! (expected 168, actual " \
                             + sum.__str__() + ")")
        
        from DjangoSite.kburndown.service import delete_task
        delete_task(None, 3)
        from DjangoSite.kburndown.service import finish_task
        finish_task(None, 4, "DONE 4")
        delete_task(None, 6)
        finish_task(None, 7, "DONE 7")
        
        sum=GraphData.objects.order_by('-date')[0].value
        self.failUnlessEqual(sum, 122, \
                             "GraphDataTest: test_recount failed on section 2! (expected 122, actual " \
                              + sum.__str__() + ")")
        
        from DjangoSite.kburndown.service import edit_task
        edit_task(None, 1, "T1(m)", "T1(cnt)", 10)
        delete_task(None, 2)
        edit_task(None, 5, "T5(m)", None, 2)
        edit_task(None, 8, "T8(m)", None, 1)
        add_task(None, "T9", None, 3, 2)
        
        sum=GraphData.objects.order_by('-date')[0].value
        self.failUnlessEqual(sum, 106, \
                             "GraphDataTest: test_recount failed on section 3! (expected 106, actual " \
                             + sum.__str__() + ")")
